﻿using OpenCompiler.AST;
using OpenCompiler.Scanning;

namespace OpenCompiler.LanguageElements
{
	public class Using : ILanguageElement
	{
		public Statement Generate(Statement statement, Token[] tokens, int tokenIndex, out int tokensUsed)
		{
			tokensUsed = 0;
			var rootStatement = statement as GlobalStatement;
			if (null != rootStatement)
			{
				var nextToken = tokens[tokenIndex + 1].ActualToken;
				tokensUsed = 0;
				if (nextToken is string)
				{
					var name = nextToken as string;
					var result = rootStatement.Using(name);
					tokensUsed++;
					return result;
				}
			}
			return statement;
		}
	}
}
